#ifndef CUSTOMMENUBUTTON_H
#define CUSTOMMENUBUTTON_H

#include <QApplication>
#include <QMainWindow>
#include <QToolBar>
#include <QPushButton>
#include <QWidget>
#include <QVBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QLabel>

class CustomMenuButton : public QWidget {
    Q_OBJECT

public:
    CustomMenuButton(QWidget *parent = nullptr) : QWidget(parent) {
        QVBoxLayout *layout = new QVBoxLayout(this);
        menuButton = new QPushButton("Menu Button", this);

        layout->addWidget(menuButton);

        // 创建一个新的QWidget来显示
        newWidget = new QWidget(this);
        newWidget->setWindowFlags(Qt::Popup);
        QGridLayout *gridLayout = new QGridLayout(newWidget);

        // 添加标签到网格布局
        QLabel *label1 = new QLabel("1", newWidget);
        QLabel *label2 = new QLabel("2", newWidget);
        gridLayout->addWidget(label1, 0, 0);
        gridLayout->addWidget(label2, 1, 0);

        // 添加按钮到网格布局
        for (int row = 0; row < 2; ++row) {
            for (int col = 1; col < 3; ++col) {
                QPushButton *button = new QPushButton(QString("Button %1-%2").arg(row).arg(col), newWidget);
                gridLayout->addWidget(button, row, col);
            }
        }

        newWidget->setLayout(gridLayout);

        connect(menuButton, &QPushButton::clicked, this, &CustomMenuButton::showNewWidget);
    }

private slots:
    void showNewWidget() {
        QPoint pos = menuButton->mapToGlobal(QPoint(0, 0));
        newWidget->move(pos);
        newWidget->show();
    }

private:
    QPushButton *menuButton;
    QWidget *newWidget;
};

#endif // CUSTOMMENUBUTTON_H
